<?php
/*if ($_GET['id_ad'] == "0")
{
    include('insert_advert.php');
}
if ($_GET['id_ad'] == "1")
{
    include('edit_advert.php');
}*/
include('admin_advert.php');
/**
 * Created by PhpStorm.
 * User: tsa
 * Date: 17/12/2013
 * Time: 11:34 πμ
 */
if (!ISSET($con))
{
    include('auth_db.php');
}

if ($_POST['click'] == "1")
{
    $sql_q = 'UPDATE `field` SET `name`="'.$_POST['name'].'",`divname`="'.$_POST['divname'].'", `parameters`="'.$_POST['parameters'].'" WHERE `id`='.intval($_POST['id']);
    $result = mysqli_query($con, $sql_q);
    echo $sql_q;
}
if ($_POST['click'] == "2")
{
    // $sql_q = 'DELETE FROM field_data WHERE field_category_action_id IN (
    // SELECT field_category_action.id FROM field_category_action, category_action WHERE field_category_action.category_id = category_action.id AND category_action.id ='.intval($_POST['id']).' )';
    $sql_q = 'DELETE FROM `field` WHERE `id`='.intval($_POST['id']);
    $result = mysqli_query($con, $sql_q);
    // $sql_q = 'DELETE FROM category';
   // echo $sql_q;
}
$click = "0";
$_POST["click"] = "0";
$sql_q = 'SELECT * FROM `field` WHERE `id` = '.$_GET['id'];
$result = mysqli_query($con, $sql_q);
$row=mysqli_fetch_array($result);
if ($_GET['id_ad'] == "2")
{
    if (!isset($_POST['parameters']))
    {
        $yo = $row['parameters'];
    }
    else
    {
        $yo = $_POST['parameters'];
    }
    $form = '<h4>Επεξεργασία πεδίου</h4>';
    $form = $form . '<form id="form_field_edit" method="post">';
    $form = $form . '<label> Name</label>';
    $form = $form . '<input name="name" type="text" value="'.$row['name'].'"/>';
    $form = $form . '<label> Divname</label>';
    $form = $form . '<input name="divname" type="text" value="'.$row['divname'].'"/>';
    $form = $form . '<input name="id" type="hidden" value="'.$row['id'].'"/>';
    $form = $form . '<label> Parameteres</label>';
    $form = $form . '<select name="parameters"/>';
    if ($yo == "NULL") {
    $form = $form . '<option selected value="NULL">NULL</option>';
    }
    else
    {
        $form = $form . '<option value="NULL">NULL</option>';
    }
    if ($yo == "TEXT") {
    $form = $form . '<option selected value="TEXT"> TEXT FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="TEXT"> TEXT FIELD</option>';
    }
    if ($yo == "RADIOBOX") {
    $form = $form . '<option selected value="RADIOBOX"> RADIOBOX FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="RADIOBOX"> RADIOBOX FIELD</option>';
    }
    if ($yo == "CHECKBOX") {
    $form = $form . '<option selected value="CHECKBOX"> CHECKBOX FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="CHECKBOX"> CHECKBOX FIELD</option>';
    }
    if ($yo == "PASSWORD") {
    $form = $form . '<option selected value="PASSWORD"> PASSWORD FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="PASSWORD"> PASSWORD FIELD</option>';
    }
    if ($yo == "MEDIA") {
    $form = $form . '<option selected value="MEDIA"> MEDIA</option>';
    }
    else
    {
        $form = $form . '<option value="MEDIA"> MEDIA</option>';
    }
    if ($yo == "MEDIA") {
    $form = $form . '<option selected value="DROPDOWNBOX"> DROP DOWN BOX FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="DROPDOWNBOX"> DROP DOWN BOX FIELD</option>';
    }
    if ($yo == "TEXTAREA") {
    $form = $form . '<option selected value="TEXTAREA"> TEXT AREA FIELD</option>';
    }
    else
    {
        $form = $form . '<option value="TEXTAREA"> TEXT AREA FIELD</option>';
    }
    $form = $form . '</select>';
    $form = $form . '<input name="click" type="hidden" value="1"/>';
    $form = $form . '<input type="submit" value="Ενημέρωση πεδίου"/>';
    $form = $form . '</form>';
    echo $form;
}
elseif ($_GET['id_ad'] == "3") {
    $form = '<h4>Διαγραφή Εγγραφής:'.$row['id'].' '.$row['name'].'</h4>';
    $form = $form . '<form id="form_category_delete" method="post">';
    $form = $form . '<input name="id" type="hidden" value="'.$row['id'].'"/>';
    $form = $form . '<input name="click" type="hidden" value="2"/>';
    $form = $form . '<input type="submit" value="Διαγραφή πεδίου"/>';
    $form = $form . '</form>';
    echo $form;
    $result = mysqli_query($con, " SELECT * FROM field group by name ");
    echo '<table border="1">';
    while($row = mysqli_fetch_array($result))
    {
        echo '<tr><td>'.$row['id'].'</td><td>'.$row['name'].'</td><td>'.$row['divname'].'</td></tr>';
    }
    echo '</table>';
}
else
{
    echo "<br><h2>PAGE NOT FOUND</h2>";
}
?>